package com.yiqi.lottery.feature.mine.view;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suozhang.framework.framework.AM;
import com.suozhang.framework.framework.BaseActivity;
import com.yiqi.lottery.R;
import com.yiqi.lottery.common.util.DateTool;
import com.yiqi.lottery.entity.bo.BalanceBo;
import com.yiqi.lottery.feature.mine.contract.BanlanceContract;
import com.yiqi.lottery.feature.mine.dependencies.banlance.BanlancePresenterModule;
import com.yiqi.lottery.feature.mine.dependencies.banlance.DaggerBanlanceComponent;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.suozhang.framework.utils.AppUtil.fullScreen;

public class AccountInfoActivity extends BaseActivity implements BanlanceContract.View {


    @BindView(R.id.toolbar)
    Toolbar mToolbar;

    @Inject
    BanlanceContract.Presenter mPresenter;
    @BindView(R.id.tv_user_banlance_money_total)
    TextView mTvUserBanlanceMoneyTotal;
    @BindView(R.id.tv_user_banlance_money_withdraw)
    TextView mTvUserBanlanceMoneyWithdraw;
    @BindView(R.id.tv_user_banlance_money_lottery)
    TextView mTvUserBanlanceMoneyLottery;
    @BindView(R.id.rv_info)
    RecyclerView rvInfo;
    InfoAdapter infoAdapter;
    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_account_info;
    }

    @Override
    protected void initInjector() {
        DaggerBanlanceComponent.builder().banlancePresenterModule(new BanlancePresenterModule(this)).build().inject(this);
    }

    @Override
    protected void initView() {
        initToolBar(mToolbar, "账户明细", true, true);
        rvInfo.setLayoutManager(new LinearLayoutManager(this));
        rvInfo.addItemDecoration(new com.suozhang.framework.component.recyclerview.DividerItemDecoration(com.suozhang.framework.component.recyclerview.DividerItemDecoration.VERTICAL).setHeight(2));
        infoAdapter=new InfoAdapter();
        infoAdapter.bindToRecyclerView(rvInfo);
    }


    @Override
    protected void initData() {
        mPresenter.getMyBanlance();
    }

    @Override
    protected void initSystemParams() {
//        super.initSystemParams();
        fullScreen(this);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    @Override
    public void showMyBanlanceSuccess(BalanceBo msg) {
        if (msg != null) {
            mTvUserBanlanceMoneyTotal.setText(msg.getBalance_amount() + "");
            mTvUserBanlanceMoneyWithdraw.setText(msg.getAvailable_amount() + "");
            mTvUserBanlanceMoneyLottery.setText(msg.getIncome_amount() + "");
            infoAdapter.setNewData(msg.getList());
        }
    }

    @Override
    public void showMyBanlanceError(String msg) {
        showErrorMsg(msg);
    }

    public class InfoAdapter extends BaseQuickAdapter<BalanceBo.ListBean,BaseViewHolder>{

        public InfoAdapter() {
            super(R.layout.item_account_info);
        }

        @Override
        protected void convert(BaseViewHolder helper, BalanceBo.ListBean item) {

            helper.setText(R.id.tv_info_money,item.getType()==2?"-"+item.getValue():"+"+item.getValue())
                    .setText(R.id.tv_info_use,item.getDesc())
                    .setText(R.id.tv_info_date, DateTool.TimeStamp2Date(item.getCreated_at()))
                    .setTextColor(R.id.tv_info_money,item.getType()==2? AM.app().getResources().getColor(R.color.primary_highlight):AM.app().getResources().getColor(R.color.color_33_e9_e9));
        }
    }
}
